// ui/utils/formatters.js

/**
 * Formats an ISO 8601 timestamp string into a more readable format.
 * Example: "YYYY-MM-DD HH:mm:ss"
 * @param {string} isoString - The ISO 8601 timestamp string.
 * @returns {string} The formatted timestamp string, or an empty string if input is invalid.
 */
function formatDisplayTimestamp(isoString) {
    if (!isoString) return '';
    try {
        const date = new Date(isoString);

        // Check if the date is valid
        if (isNaN(date.getTime())) {
            console.warn(`Invalid date string received: ${isoString}`);
            return isoString; // Return original string or some error indicator
        }

        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');

        // For now, always return "YYYY-MM-DD HH:mm:ss"
        // Logic to show only HH:mm for today can be added later if needed.
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    } catch (error) {
        console.error(`Error formatting timestamp "${isoString}":`, error);
        return isoString; // Fallback to original string on error
    }
}

// Export the function if using ES modules (though the project seems to use http-vue-loader which might not directly support this)
// For http-vue-loader, functions are typically made available globally or on a Vue instance.
// However, to make it importable in other plain JS files if needed, or for future refactoring:
if (typeof module !== 'undefined' && module.exports) {
    module.exports = { formatDisplayTimestamp };
} else if (typeof define === 'function' && define.amd) {
    define([], function() {
        return { formatDisplayTimestamp };
    });
}
// If no module system, it will be a global function.
// For the current setup with http-vue-loader, we'll likely need to ensure this function
// is accessible within the Vue components, perhaps by attaching it to the window object
// or by loading it in a way that http-vue-loader can pick it up.
// For simplicity in the context of http-vue-loader, we might need to adjust how it's imported/used in components.
// Let's assume for now that components can access it if the script is loaded.
// A common pattern with http-vue-loader is to define utilities and then attach them to Vue.prototype or use them directly if in scope.

// Given the project structure, it's more likely that components will directly include/reference this.
// Let's make it a global function for now for simplicity with the current setup.
window.formatDisplayTimestamp = formatDisplayTimestamp;